home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / plotting / pcgplots / gptdisp.cpp < prev    next >
C/C++ Source or Header  |  1992-04-24  |  20KB  |  871 lines

  1. // GptDisp.cpp -  pcGPlot display classes
  2. // copyright 1992 Pittsburgh Supercomputing Center
  3. #include  "gpt.h"
  4. #include  "cgm.h" // basic display classes
  5. #include  "cgmdisp.h" // basic display classes
  6. #include  "gptDisp.h"
  7.  
  8. extern void myError(const char*, const char *msg2 = NULL, int severity = 1);
  9. const float pcScale     = .5;   // PC Scale factor for line, edge width
  10. const unsigned long PAL = 0X2000000 ;
  11. const int DEFAULT_INDEX = 1;
  12. int set_color2( COLORREF *out, const genColr &in);
  13.  
  14.  
  15. // *** pcDisplay::pcDisplay -  Constructor
  16. pcDisplay::pcDisplay(CgmWindowPt win, HDC hdc, HDC hdcMeta,
  17.                           HDC hdcInfo, RECT *rect) : baseDisplay() // constructor
  18.     {
  19.     BOOL hoho;
  20.     this->cgmWin = win;
  21.     this->hdc    = hdc;
  22.     this->hdcMeta = hdcMeta;
  23.     myPxlExtent  = new vdcPts(0, 0, (int)rect->right  , (int)rect->bottom);
  24.  
  25.     int horzsize = GetDeviceCaps(hdcInfo,HORZSIZE);  // Width in millimeters
  26.     int vertsize = GetDeviceCaps(hdcInfo,VERTSIZE);  // Height in millimeters
  27.     int horzres  = GetDeviceCaps(hdcInfo,HORZRES);   // Width in pixels
  28.     int vertres  = GetDeviceCaps(hdcInfo,VERTRES);   // Height in raster lines
  29.     myxPxlSize   = (double)horzsize/horzres;  // mm/pix
  30.     myyPxlSize   = (double)vertsize/vertres;  // mm/pix
  31.  
  32.  
  33.     RGBbackground= RGB(0XFF,0XFF,0XFF) | PAL;  // white background
  34.     Index1Set = FALSE;
  35.     edgeseen      = FALSE;        // edge not seen
  36.     solidpoly     = TRUE;         // polygon interior filled
  37.     hollowpoly    = FALSE;        // ??
  38.  
  39.     useclip       = TRUE;         // use a clipping rectangle
  40.     clipr         = *rect;
  41.     noElements    = 0;            // # of elements drawn
  42.  
  43.   lLinePen.lopnStyle   = PS_SOLID;
  44.   lLinePen.lopnWidth.x = 1;
  45.   lLinePen.lopnColor   = RGB(0,0,0) | PAL;
  46.  
  47.   lMarkerPen = lTextPen = lEdgePen = lLinePen;
  48.  
  49.   UseLinePen = TRUE;
  50.   lFillBrush.lbStyle = BS_SOLID;
  51.   lFillBrush.lbColor = RGB(255,255,255) | PAL;
  52.  
  53.   hLinePen               = CreatePenIndirect((LOGPEN FAR *)&lLinePen);
  54.   hEdgePen               = CreatePenIndirect((LOGPEN FAR *)&lEdgePen);
  55.   hTextPen               = CreatePenIndirect((LOGPEN FAR *)&lTextPen);
  56.   hMarkerPen         = CreatePenIndirect((LOGPEN FAR *)&lMarkerPen);
  57.   hHollowPen             = NULL;
  58.   hFillBrush             = CreateBrushIndirect((LOGBRUSH FAR *)&lFillBrush);
  59.   hBackgroundBrush     = NULL;
  60.   LinePenOK             = TRUE;
  61.   EdgePenOK             = TRUE;
  62.   TextPenOK             = TRUE;
  63.   MarkerPenOK        = TRUE;
  64.   FillBrushOK           = TRUE;
  65.  
  66.   hPenOrig      = SelectObject(hdc, (HANDLE)hLinePen);
  67.   SelectObject(hdcMeta, (HANDLE)hLinePen);
  68.   hPenUsed       = hLinePen;
  69.  
  70.   hBrushOrig   = SelectObject(hdc, (HANDLE)hFillBrush);
  71.   SelectObject(hdcMeta, (HANDLE)hFillBrush);
  72.  
  73.   hBrushUsed = hFillBrush;
  74.  
  75.   SetBkMode(hdc,     TRANSPARENT);
  76.   SetBkMode(hdcMeta, TRANSPARENT);
  77.  
  78. #ifdef MAKEDEFPALETTE
  79.   LOGPALETTE *pal = pcDisplay::MakeDefaultPalette();
  80.   HPALETTE hPal = CreatePalette((LPLOGPALETTE)pal);
  81.   HPALETTE foo = SelectPalette(hdc,hPal,0);
  82.   HPALETTE moo = SelectPalette(hdcMeta, hPal,0);
  83.   if (cgmWin->hPal)
  84.         {
  85.         hoho = DeleteObject(cgmWin->hPal);
  86.         delete cgmWin->pPalette;
  87.         }
  88.   cgmWin->hPal = hPal;
  89.   cgmWin->pPalette = pal;
  90.   int yoyo = RealizePalette(hdc);
  91.   int zoo = RealizePalette(hdcMeta);
  92. #else
  93.   if (cgmWin->hPal)
  94.         {
  95.         UnrealizeObject(cgmWin->hPal);
  96.         DeleteObject(cgmWin->hPal);
  97.         delete cgmWin->pPalette;
  98.         cgmWin->hPal = NULL;
  99.         cgmWin->pPalette = NULL;
  100.         }
  101.  
  102. #endif
  103.  
  104.   }
  105.  
  106. // *** pcDisplay::MakeDefaultPalette()
  107. LOGPALETTE *pcDisplay::MakeDefaultPalette()
  108.     {
  109.     // Play making initial palette !!!!!
  110.     BYTE red, green, blue;
  111.     int i;
  112.     LOGPALETTE *pal;
  113.     pal = (LOGPALETTE *)(new char[sizeof(LOGPALETTE) +
  114.                                           ( sizeof(PALETTEENTRY)* 216) ]);
  115.     pal->palNumEntries = 216;
  116.     pal->palVersion = 0X300;
  117.     red = green = blue = (BYTE)0;
  118.     BYTE mycol[6] = {0,50, 100, 150, 200, 250};
  119.     int j,k,l;
  120.     for (i = 0,j = 0; j < 6; j++)
  121.         {
  122.         red = mycol[j];
  123.         for ( k = 0; k < 6; k++)
  124.             {
  125.             green = mycol[k];
  126.             for ( l = 0; l < 6; l++)
  127.                 {
  128.                 blue = mycol[l];
  129.                 pal->palPalEntry[i].peRed   =  red;
  130.                 pal->palPalEntry[i].peGreen =  green;
  131.                 pal->palPalEntry[i].peBlue  =  blue;
  132.                 pal->palPalEntry[i].peFlags =  (BYTE)0;
  133.                 i++;
  134.                 }
  135.             }
  136.         }
  137.     return pal;
  138.     }
  139.  
  140.  
  141. // *** pcDisplay::~pcDisplay
  142. pcDisplay::~pcDisplay() // destructor
  143.      {
  144.             // printf("vdc = %f, %f\n", vdcWidth, vdcHeight);
  145.  
  146.      delete myPxlExtent;
  147.      SelectObject(hdc, hPenOrig);
  148.      SelectObject(hdc, hBrushOrig );
  149.      DeleteObject(hLinePen);
  150.      DeleteObject(hEdgePen);
  151.      DeleteObject(hTextPen);
  152.      DeleteObject(hMarkerPen);
  153.      DeleteObject(hFillBrush);
  154.      DeleteObject(hBackgroundBrush);
  155.      if (hHollowPen) DeleteObject(hHollowPen);
  156.      }
  157.  
  158. // *** pcDisplay::SetLinePen()
  159. void pcDisplay::SetLinePen()
  160.     {
  161.     UseLinePen = TRUE;
  162.     if (LinePenOK)
  163.         {
  164.         if (hPenUsed != hLinePen)
  165.             {
  166.             SelectObject(hdc,     (HANDLE)hLinePen);
  167.             SelectObject(hdcMeta, (HANDLE)hLinePen);
  168.             hPenUsed = hLinePen;
  169.             }
  170.         return;
  171.         }
  172.     else
  173.         {
  174.         LinePenOK = TRUE;
  175.         HPEN  hPen  = CreatePenIndirect((LOGPEN FAR *)&lLinePen);
  176.         SelectObject(hdc,     (HANDLE)hPen);
  177.         SelectObject(hdcMeta, (HANDLE)hPen);
  178.         DeleteObject(hLinePen);
  179.         hLinePen = hPen;
  180.         hPenUsed = hLinePen;
  181.         }
  182.     }
  183.  
  184. // *** pcDisplay::SetEdgePen()
  185. void pcDisplay::SetEdgePen()
  186.     {
  187.     if (EdgePenOK)
  188.         {
  189.         if (hPenUsed != hEdgePen)
  190.             {
  191.             SelectObject(hdc,     (HANDLE)hEdgePen);
  192.             SelectObject(hdcMeta, (HANDLE)hEdgePen);
  193.             hPenUsed = hEdgePen;
  194.             }
  195.         return;
  196.         }
  197.     else
  198.         {
  199.         EdgePenOK = TRUE;
  200.         HPEN  hPen  = CreatePenIndirect((LOGPEN FAR *)&lEdgePen);
  201.         SelectObject(hdc,     (HANDLE)hPen);
  202.         SelectObject(hdcMeta, (HANDLE)hPen);
  203.         DeleteObject(hEdgePen);
  204.         hEdgePen = hPen;
  205.         hPenUsed = hEdgePen;
  206.         }
  207.     }
  208.  
  209. // *** pcDisplay::SetTextPen()
  210. void pcDisplay::SetTextPen()
  211.     {
  212.     if (TextPenOK)
  213.         {
  214.         if (hPenUsed != hTextPen)
  215.             {
  216.             SelectObject(hdc,     (HANDLE)hTextPen);
  217.             SelectObject(hdcMeta, (HANDLE)hTextPen);
  218.             hPenUsed = hTextPen;
  219.             }
  220.         return;
  221.         }
  222.     else
  223.         {
  224.         TextPenOK = TRUE;
  225.         HPEN  hPen  = CreatePenIndirect((LOGPEN FAR *)&lTextPen);
  226.         SelectObject(hdc,     (HANDLE)hPen);
  227.         SelectObject(hdcMeta, (HANDLE)hPen);
  228.         DeleteObject(hTextPen);
  229.         hTextPen = hPen;
  230.         hPenUsed = hTextPen;
  231.         }
  232.     }
  233.  
  234. // *** pcDisplay::SetMarkerPen()
  235. void pcDisplay::SetMarkerPen()
  236.     {
  237.     if (MarkerPenOK)
  238.         {
  239.         if (hPenUsed != hMarkerPen)
  240.             {
  241.             SelectObject(hdc,     (HANDLE)hMarkerPen);
  242.             SelectObject(hdcMeta, (HANDLE)hMarkerPen);
  243.             hPenUsed = hMarkerPen;
  244.             }
  245.         return;
  246.         }
  247.     else
  248.         {
  249.         MarkerPenOK = TRUE;
  250.         HPEN  hPen  = CreatePenIndirect((LOGPEN FAR *)&lMarkerPen);
  251.         SelectObject(hdc,     (HANDLE)hPen);
  252.         SelectObject(hdcMeta, (HANDLE)hPen);
  253.         DeleteObject(hMarkerPen);
  254.         hMarkerPen = hPen;
  255.         hPenUsed = hMarkerPen;
  256.         }
  257.     }
  258.  
  259. // *** pcDisplay::SetFillBrush()
  260. void pcDisplay::SetFillBrush()
  261.     {
  262.     if (FillBrushOK)
  263.         {
  264.         if (hBrushUsed != hFillBrush)
  265.             {
  266.             SelectObject(hdc,     (HANDLE)hFillBrush);
  267.             SelectObject(hdcMeta, (HANDLE)hFillBrush);
  268.             hBrushUsed = hFillBrush;
  269.             }
  270.         return;
  271.         }
  272.     else
  273.         {
  274.         FillBrushOK = TRUE;
  275.         HBRUSH hBrush  = CreateBrushIndirect((LOGBRUSH FAR *)&lFillBrush);
  276.         SelectObject(hdc,     (HANDLE)hBrush);
  277.         SelectObject(hdcMeta, (HANDLE)hBrush);
  278.         DeleteObject(hFillBrush);
  279.         hFillBrush = hBrush;
  280.         hBrushUsed = hFillBrush;
  281.         }
  282.     }
  283. // *** pcDisplay::SetBackBrush()
  284.  void
  285.  pcDisplay::SetBackBrush(COLORREF RGB)
  286.     {
  287.     LOGBRUSH lBrush;
  288.     lBrush.lbStyle = BS_SOLID;
  289.     lBrush.lbColor = RGB | PAL;
  290.     HBRUSH hBrush  = CreateBrushIndirect((LOGBRUSH FAR *)&lBrush);
  291.     SelectObject(hdc,     (HANDLE)hBrush);
  292.     SelectObject(hdcMeta, (HANDLE)hBrush);
  293.     if (hBackgroundBrush) DeleteObject( hBackgroundBrush);
  294.     hBackgroundBrush = hBrush;
  295.     hBrushUsed = NULL;
  296.     }
  297.  
  298. // *** pcDisplay::SetHollowPen()
  299. void pcDisplay::SetHollowPen(COLORREF RGB)
  300.     {
  301.     LOGPEN lPen;
  302.     lPen.lopnStyle     = PS_SOLID;
  303.     lPen.lopnWidth.x   = 1;
  304.     lPen.lopnColor     = RGB |= PAL;
  305.     HPEN hPen          = CreatePenIndirect((LOGPEN FAR *)&lPen);
  306.     SelectObject(hdc,     (HANDLE)hPen);
  307.     SelectObject(hdcMeta, (HANDLE)hPen);
  308.     if ( hHollowPen) DeleteObject( hHollowPen);
  309.     hHollowPen = hPen;
  310.     hPenUsed   = NULL;
  311.  
  312.     }
  313. // *** pcDisplay::backColr
  314.  void
  315.  pcDisplay::backColr(const genColr &inColr)
  316.     {
  317.     set_color2(&RGBbackground, inColr);
  318.     backColr2();
  319.     }
  320.  
  321.  void
  322.  pcDisplay::backColr2()
  323.     {
  324.     if ( noElements == 0)
  325.         {
  326.         SetBackBrush(RGBbackground);
  327.         SetHollowPen(RGBbackground);
  328.  
  329.         Rectangle(hdc, itsExtent.left, itsExtent.top,
  330.                                                       itsExtent.right, itsExtent.bottom);
  331.         Rectangle(hdcMeta, itsExtent.left, itsExtent.top,
  332.                                                       itsExtent.right, itsExtent.bottom);
  333.         //SetLinePen();
  334.         if (!Index1Set) adjustPens();
  335.         }
  336.     }
  337.  
  338.  void
  339.  pcDisplay::adjustPens()
  340.     {
  341.     if ( RGBbackground == lLinePen.lopnColor)
  342.         {
  343.         lLinePen.lopnColor = (~lLinePen.lopnColor & (long)0XFFFFFF) | PAL;
  344.         LinePenOK = FALSE;
  345.         }
  346.     if ( RGBbackground == lEdgePen.lopnColor)
  347.         {
  348.         lEdgePen.lopnColor = (~lEdgePen.lopnColor & (long)0XFFFFFF) | PAL;
  349.         EdgePenOK = FALSE;
  350.         }
  351.     if ( RGBbackground == lTextPen.lopnColor)
  352.         {
  353.         lTextPen.lopnColor = (~lTextPen.lopnColor & (long)0XFFFFFF) | PAL;
  354.         TextPenOK = FALSE;
  355.         }
  356.     if ( RGBbackground == lMarkerPen.lopnColor)
  357.         {
  358.         lMarkerPen.lopnColor = (~lMarkerPen.lopnColor & (long)0XFFFFFF) | PAL;
  359.         MarkerPenOK = FALSE;
  360.         }
  361.     if ( RGBbackground == lFillBrush.lbColor)
  362.         {
  363.         lFillBrush.lbColor = (~lFillBrush.lbColor & (long)0XFFFFFF) | PAL;
  364.         FillBrushOK = FALSE;
  365.         }
  366.     }
  367.  
  368. // *** pcDisplay::edgeColr
  369.  void
  370.  pcDisplay::edgeColr(const genColr &inColr)
  371.      {
  372.      COLORREF RGB;
  373.  
  374.      myEdgeIndex = set_color2(&RGB, inColr);
  375.      if ( RGB != lEdgePen.lopnColor)
  376.         {
  377.         lEdgePen.lopnColor = RGB;
  378.         EdgePenOK = FALSE;
  379.         }
  380.      }
  381.  
  382.  
  383. // *** pcDisplay::fillColr
  384. // establish a fill colour
  385.  void
  386.  pcDisplay::fillColr(const genColr &inColr)
  387.      {
  388.      COLORREF RGB;
  389.  
  390.      myFillIndex = set_color2(&RGB, inColr);
  391.      if ( RGB != lFillBrush.lbColor)
  392.         {
  393.         lFillBrush.lbColor = RGB;
  394.         FillBrushOK = FALSE;
  395.         }
  396.      }
  397.  
  398.  
  399.  
  400.  
  401. // *** pcDisplay::lineColr
  402.  void
  403.  pcDisplay::lineColr(const genColr &inColr  )
  404.      {
  405.      COLORREF RGB;
  406.  
  407.      myLineIndex = set_color2(&RGB, inColr);
  408.      if ( RGB != lLinePen.lopnColor)
  409.         {
  410.         lLinePen.lopnColor = RGB;
  411.         LinePenOK = FALSE;
  412.         }
  413.      }
  414.  
  415. // *** pcDisplay::textColr
  416.  void
  417.  pcDisplay::textColr(const genColr &inColr  )
  418.      {
  419.      COLORREF RGB;
  420.  
  421.      myTextIndex = set_color2(&RGB, inColr);
  422.      if ( RGB != lTextPen.lopnColor)
  423.         {
  424.         lTextPen.lopnColor = RGB;
  425.         TextPenOK = FALSE;
  426.         }
  427.      }
  428.  
  429. // *** pcDisplay::markerColr
  430.  void
  431.  pcDisplay::markerColr(const genColr &inColr  )
  432.      {
  433.      COLORREF RGB;
  434.  
  435.      myMarkerIndex = set_color2(&RGB, inColr);
  436.      if ( RGB != lMarkerPen.lopnColor)
  437.         {
  438.         lMarkerPen.lopnColor = RGB;
  439.         MarkerPenOK = FALSE;
  440.         }
  441.      }
  442.  
  443.  
  444. // ***  pcDisplay::intStyle
  445. // interior style
  446. ////
  447.  
  448.  void
  449.  pcDisplay::intStyle(int inStyle)
  450.      {
  451.      switch (inStyle)
  452.         {
  453.         case 0: // hollow  - don't fill but if not edgeseen, edge in fill color
  454.         hollowpoly = TRUE;
  455.         solidpoly = FALSE;
  456.         break;
  457.  
  458.         case 1: // solid
  459.         hollowpoly = FALSE;
  460.         solidpoly = TRUE;
  461.         if (  lFillBrush.lbStyle != BS_SOLID)
  462.             {   lFillBrush.lbStyle = BS_SOLID; FillBrushOK = FALSE; }
  463.         break;
  464.  
  465.         case 2: // pattern
  466.         hollowpoly = FALSE;
  467.         solidpoly = TRUE;
  468.         if (  lFillBrush.lbStyle != BS_HATCHED || lFillBrush.lbHatch != HS_DIAGCROSS)
  469.             {
  470.             lFillBrush.lbStyle = BS_HATCHED;
  471.             lFillBrush.lbHatch = HS_DIAGCROSS;
  472.             FillBrushOK = FALSE;
  473.             }
  474.         break;
  475.  
  476.         case 3: // hatch
  477.         hollowpoly = FALSE;
  478.         solidpoly = TRUE;
  479.         if (  lFillBrush.lbStyle != BS_HATCHED || lFillBrush.lbHatch != HS_FDIAGONAL  )
  480.             {
  481.             lFillBrush.lbStyle = BS_HATCHED;
  482.             lFillBrush.lbHatch = HS_FDIAGONAL;
  483.             FillBrushOK = FALSE;
  484.             }
  485.         break;
  486.  
  487.         case 4: // empty - don't fill, do edge if edgeseen
  488.         hollowpoly = FALSE;
  489.         solidpoly  = FALSE;
  490.         break;
  491.         }
  492.     }
  493.  
  494.  
  495. // *** pcDisplay::edgeVis
  496.  void
  497.  pcDisplay::edgeVis(int inVis)
  498.      {
  499.  
  500.      if ( inVis) edgeseen = TRUE;
  501.      else        edgeseen  = FALSE;
  502.      }
  503.  
  504.  
  505. // *** pcDisplay::lineType
  506.  void
  507.  pcDisplay::lineType(int inType)
  508.     {
  509.     switch (inType )
  510.         {
  511.         case 1:
  512.         if (lLinePen.lopnStyle != PS_SOLID)
  513.             { lLinePen.lopnStyle = PS_SOLID; LinePenOK = FALSE; }
  514.         break;
  515.  
  516.         case 2:
  517.         if (lLinePen.lopnStyle != PS_DASH)
  518.             { lLinePen.lopnStyle = PS_DASH; LinePenOK = FALSE; }
  519.         break;
  520.  
  521.         case 3:
  522.         if (lLinePen.lopnStyle != PS_DOT)
  523.             { lLinePen.lopnStyle = PS_DOT; LinePenOK = FALSE; }
  524.         break;
  525.  
  526.         case 4:
  527.         if (lLinePen.lopnStyle != PS_DASHDOT)
  528.             { lLinePen.lopnStyle = PS_DASHDOT; LinePenOK = FALSE; }
  529.         break;
  530.  
  531.         case 5:
  532.         if (lLinePen.lopnStyle != PS_DASHDOTDOT)
  533.             { lLinePen.lopnStyle = PS_DASHDOTDOT; LinePenOK = FALSE; }
  534.         break;
  535.  
  536.         }
  537.     baseDisplay::lineType(inType);
  538.     }
  539.  
  540. // *** pcDisplay::edgeType
  541.  void
  542.  pcDisplay::edgeType(int inType)
  543.     {
  544.     switch (inType )
  545.         {
  546.         case 1:
  547.         if (lEdgePen.lopnStyle != PS_SOLID)
  548.             { lEdgePen.lopnStyle = PS_SOLID; EdgePenOK = FALSE; }
  549.         break;
  550.  
  551.         case 2:
  552.         if (lEdgePen.lopnStyle != PS_DASH)
  553.             { lEdgePen.lopnStyle = PS_DASH; EdgePenOK = FALSE; }
  554.         break;
  555.  
  556.         case 3:
  557.         if (lEdgePen.lopnStyle != PS_DOT)
  558.             { lEdgePen.lopnStyle = PS_DOT; EdgePenOK = FALSE; }
  559.         break;
  560.  
  561.         case 4:
  562.         if (lEdgePen.lopnStyle != PS_DASHDOT)
  563.             { lEdgePen.lopnStyle = PS_DASHDOT; EdgePenOK = FALSE; }
  564.         break;
  565.  
  566.         case 5:
  567.         if (lEdgePen.lopnStyle != PS_DASHDOTDOT)
  568.             { lEdgePen.lopnStyle = PS_DASHDOTDOT; EdgePenOK = FALSE; }
  569.         break;
  570.  
  571.         }
  572.     baseDisplay::edgeType(inType);
  573.     }
  574.  
  575.  
  576. // ***  pcDisplay::lineWidth
  577.  
  578.  void
  579.  pcDisplay::lineWidth(const vdcR *inWidth)
  580.     {
  581.     baseDisplay::lineWidth(inWidth);
  582.     int lWidth; // line width we shall use
  583.     if (myLineWidth->type()) { // relative size
  584.         lWidth = (int) (  myLineWidth->f()*pcScale); // use 1 as default
  585.         }
  586.     else { // got a vdc
  587.         lWidth = getSize(myLineWidth->v());
  588.         }
  589.     if (lWidth < 1) lWidth = 1;
  590.     lLinePen.lopnWidth.x =  lWidth;
  591.     LinePenOK = FALSE;
  592.  
  593.     }
  594.  
  595.  
  596. // *** pcDisplay::edgeWidth
  597.  void
  598.  pcDisplay::edgeWidth(const vdcR *inWidth)
  599.      {
  600.      baseDisplay::edgeWidth(inWidth);
  601.      int lWidth; // line width we shall use
  602.      if (myEdgeWidth->type()) { // relative size
  603.          lWidth = (int) ( myEdgeWidth->f()*pcScale); // use 1 as default
  604.          }
  605.     else { // got a vdc
  606.          lWidth = getSize(myEdgeWidth->v());
  607.          }
  608.      if (lWidth < 1) lWidth = 1;
  609.      lEdgePen.lopnWidth.x = lWidth;
  610.      EdgePenOK = FALSE;
  611.     }
  612.  
  613.  
  614.  
  615. // **************************** pcDisplay::polyline *******************************
  616.  int
  617.  pcDisplay::polyline(const vdcPts *inPts) // display a polyline
  618.      {
  619.      int *scaledPtr;
  620.  
  621.      getPts(inPts, scaledPtr); // get the scaled version
  622.      if (!scaledPtr) {
  623.          myError("couldn't get scaled points");
  624.          return 0;
  625.          }
  626.      if (UseLinePen) SetLinePen();
  627.      Polyline(hdc, (LPPOINT)scaledPtr, inPts->no());
  628.      Polyline(hdcMeta, (LPPOINT)scaledPtr, inPts->no());
  629.      delete scaledPtr;
  630.  
  631.      noElements++;
  632.      return 1;
  633.      }
  634.  
  635. // ***  pcDisplay::polygon
  636.  int
  637.  pcDisplay::polygon(const vdcPts *inPts) // display a polyline
  638.      {
  639.      int *scaledPtr;
  640.  
  641.      //  if (inPts->myType)     float *floatPtr = (float *) inPts->myPtr;
  642.      //  else                   int *intPtr = (int *) inPts->myPtr;
  643.      getPts(inPts, scaledPtr,1); // get the scaled version with extra point to close
  644.      if (!scaledPtr) {
  645.          myError("couldn't get scaled points");
  646.          return 0;
  647.          }
  648.      if (solidpoly)
  649.         {
  650.         SetFillBrush();
  651.         SetHollowPen(lFillBrush.lbColor);
  652.         Polygon(hdc, (LPPOINT)scaledPtr, inPts->no());
  653.         Polygon(hdcMeta, (LPPOINT)scaledPtr, inPts->no());
  654.         }
  655.      if (edgeseen )
  656.         {
  657.         SetEdgePen();
  658.         UseLinePen = FALSE;
  659.         Polyline(hdc, (LPPOINT)scaledPtr, inPts->no()+1);
  660.         Polyline(hdcMeta, (LPPOINT)scaledPtr, inPts->no()+1);
  661.         UseLinePen = TRUE;
  662.         }
  663.      else if (hollowpoly )
  664.         {
  665.  
  666.         SetHollowPen(lFillBrush.lbColor);
  667.         UseLinePen = FALSE;
  668.         Polyline(hdc, (LPPOINT)scaledPtr, inPts->no());
  669.         Polyline(hdcMeta, (LPPOINT)scaledPtr, inPts->no());
  670.         UseLinePen = TRUE;
  671.         }
  672.  
  673.      delete scaledPtr;
  674.      noElements++;
  675.      return 1;
  676.      }
  677.  
  678. // *** pcDisplay::text
  679.  int
  680.  pcDisplay::text(const genText *gen)
  681.      {
  682.      SetTextPen();
  683.      UseLinePen = FALSE;
  684.      int ret =  baseDisplay::text(gen);
  685.      UseLinePen = TRUE;
  686.      return ret;
  687.      }
  688.   // *** pcDisplay::polymarker
  689.  int
  690.  pcDisplay::polymarker(const vdcPts *vdc)
  691.      {
  692.      SetMarkerPen();
  693.      UseLinePen = FALSE;
  694.      int ret =  baseDisplay::polymarker(vdc);
  695.      UseLinePen = TRUE;
  696.      return ret;
  697.      }
  698.  
  699.  
  700. // ***  pcDisplay::clipRect
  701.  void
  702.  pcDisplay::clipRect(const vdcPts *inPts)
  703.      {
  704.      if (inPts->no() < 2) {
  705.          myError("not enough points for clipping rectangle");
  706.          return;
  707.          }
  708.      short *scaledPtr;
  709.  
  710.      getPts(inPts, scaledPtr); // get the scaled version
  711.      if (!scaledPtr) {
  712.          myError("couldn't get scaled points");
  713.          return;
  714.          }
  715.      if (scaledPtr[0] < scaledPtr[2])
  716.          {
  717.         clipr.left  = scaledPtr[0] -1;
  718.         clipr.right = scaledPtr[2]+1;
  719.         }
  720.      else
  721.          {
  722.          clipr.left  = scaledPtr[2] -1;
  723.          clipr.right = scaledPtr[0] +1;
  724.          }
  725.      if (scaledPtr[1] < scaledPtr[3])
  726.          {
  727.          clipr.top    = scaledPtr[1] -1;
  728.          clipr.bottom = scaledPtr[3] +1;
  729.          }
  730.      else
  731.          {
  732.          clipr.top    = scaledPtr[3] -1;
  733.          clipr.bottom = scaledPtr[1] +1;
  734.          }
  735.      if (this->useclip)
  736.         {
  737.         HRGN clip = CreateRectRgnIndirect(&clipr);
  738.         SelectObject(hdc, clip);
  739.         SelectObject(hdcMeta, clip);
  740.         DeleteObject(clip);
  741.         }
  742.      delete scaledPtr;
  743.     }
  744.  
  745.  
  746.  
  747. // ***  pcDisplay::clip
  748. // turn clipping on or off
  749. ////
  750.  void
  751.  pcDisplay::clip(int inClip)
  752.      {
  753.      HRGN clip;
  754.      if (inClip)
  755.          {
  756.         this->useclip = TRUE;   // and if a clip rectangle, establish it
  757.         clip = CreateRectRgnIndirect(&clipr);
  758.         SelectObject(hdc, clip);
  759.         SelectObject(hdcMeta, clip);
  760.         DeleteObject(clip);
  761.         }
  762.      else
  763.         {
  764.         this->useclip = FALSE;  // establish default clip rectangle
  765.         clip = CreateRectRgnIndirect(&itsExtent);
  766.         SelectObject(hdc, clip);
  767.         SelectObject(hdcMeta, clip);
  768.         DeleteObject(clip);
  769.         }
  770.  
  771.      }
  772.  
  773.  
  774. // *** pcDisplay::colrs
  775.  void
  776.  pcDisplay::colrs(const colrTable *inTable)
  777.      {
  778.      BOOL hoho;
  779.      int i;
  780.      LOGPALETTE *pal, *oldPal;
  781.      int oldSize = 0;
  782.      if (cgmWin->pPalette)
  783.         {
  784.         oldPal  = cgmWin->pPalette;
  785.         oldSize = oldPal->palNumEntries;
  786.         }
  787.      int start = inTable->start();
  788.      int no    = inTable->no();
  789.      int newSize = start + no;
  790.      if (newSize < oldSize) newSize = oldSize;
  791.      pal = (LOGPALETTE *)(new char[sizeof(LOGPALETTE) +
  792.                                           ( sizeof(PALETTEENTRY)*newSize) ]);
  793.      pal->palNumEntries = newSize;
  794.      pal->palVersion = 0X300;
  795.      if (oldSize)
  796.         for (i = 0; i < oldSize; i++)
  797.             pal->palPalEntry[i] = oldPal->palPalEntry[i];
  798.  
  799.      for (i= start; i< (start + no) ; ++i)
  800.         {
  801.         pal->palPalEntry[i].peRed   =  inTable->r(i)[0]  * 0XFF;
  802.         pal->palPalEntry[i].peGreen =  inTable->r(i)[1]  * 0XFF;
  803.         pal->palPalEntry[i].peBlue  =  inTable->r(i)[2]  * 0XFF;
  804.         pal->palPalEntry[i].peFlags =  NULL;
  805.         if (myEdgeIndex == i)  edgeColr(genColr(i, inTable->extent(), inTable));
  806.         if (myLineIndex == i)  lineColr(genColr(i, inTable->extent(), inTable));
  807.         if (myTextIndex == i)  textColr(genColr(i, inTable->extent(), inTable));
  808.         if (myFillIndex == i)  fillColr(genColr(i, inTable->extent(), inTable));
  809.         if (myMarkerIndex == i)  markerColr(genColr(i, inTable->extent(), inTable));
  810.         }
  811.     HPALETTE hPal = CreatePalette((LPLOGPALETTE)pal);
  812.     HPALETTE foo = SelectPalette(hdc,hPal,0);
  813.     HPALETTE moo = SelectPalette(hdcMeta, hPal,0);
  814.     if (cgmWin->hPal)
  815.         {
  816.         hoho = DeleteObject(cgmWin->hPal);
  817.         delete cgmWin->pPalette;
  818.         }
  819.     cgmWin->hPal = hPal;
  820.     cgmWin->pPalette = pal;
  821.     int yoyo = RealizePalette(hdc);
  822.     int zoo = RealizePalette(hdcMeta);
  823.     if (1 >=start && 1 <= (start+no)) Index1Set = TRUE;
  824.     if (start == 0) backColr(genColr(0, inTable->extent(), inTable));
  825.     }
  826.  
  827.  
  828.  
  829.  
  830.  
  831. // ***  set_color2()
  832.  const
  833.   int set_color2( COLORREF *RGBOut, const genColr &genIn)
  834.      {
  835.     BYTE red, green, blue;
  836.     red    =  (BYTE)(genIn.r(0) * 0XFF);
  837.     blue   =  (BYTE)(genIn.r(1) * 0XFF);
  838.     green  =  (BYTE)(genIn.r(2) * 0XFF);
  839.  
  840.     *RGBOut   = RGB(red, blue, green) | PAL ;
  841.     if (!genIn.type()) return genIn.i();
  842.     else return DEFAULT_INDEX;
  843.     }
  844.  
  845.  void
  846.  pcDisplay::ExtentRect()
  847.     {
  848.     RECT rect;
  849.     getExtent( &rect);
  850.     lLinePen.lopnStyle = PS_SOLID;
  851.     lLinePen.lopnWidth.x = 5;
  852.     lLinePen.lopnColor = RGB(0xFF,0,0);
  853.     lLinePen.lopnColor  |= PAL;
  854.     LinePenOK = FALSE;
  855.     SetLinePen();
  856.     POINT *points = new POINT[5];
  857.     points[0].x = rect.left;
  858.     points[0].y = rect.top;
  859.     points[1].x = rect.right;
  860.     points[1].y = rect.top;
  861.     points[2].x = rect.right;
  862.     points[2].y = rect.bottom;
  863.     points[3].x = rect.left;
  864.     points[3].y = rect.bottom;
  865.     points[4] = points[0];
  866.     Polyline(hdc, points, 5 );
  867.     Polyline(hdcMeta, points, 5);
  868.     delete points;
  869.     }
  870.  
  871.